package com.anjubao.parking.municipal.roadside.controller;

import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.common.exception.ServiceException;
import com.anjubao.parking.municipal.roadside.constant.LedEnum;
import com.anjubao.parking.municipal.roadside.constant.LockEnum;
import com.anjubao.parking.municipal.roadside.service.DeviceOperationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 下发指令/操作视频桩 controller
 * @author zhuchunfeng
 * @date 2019/6/13 13:52
 */

@RestController
@RequestMapping("/parking-roadside-operation")
@Slf4j
@Api(tags = "操作视频桩")
public class DeviceOperationController {

    @Resource
    private DeviceOperationService deviceOperationService;

    @PostMapping("/manualsynctime")
    @ApiOperation("手动对时下发")
    public ApiResult manualSyncTime(@ApiParam("设备id") @RequestParam(defaultValue = "100001") String deviceId){
        deviceOperationService.manualSyncTime(deviceId);
        return ApiResult.success();

    }

    @PostMapping("manualsnapctrl")
    @ApiOperation("手动抓拍")
    public ApiResult manualsnapctrl(@ApiParam("设备id") @RequestParam(defaultValue = "100001") String deviceId){
        deviceOperationService.manualsnapctrl(deviceId);
        return ApiResult.success();

    }

    @PostMapping("berthnum")
    @ApiOperation("泊位号下发")
    public ApiResult berthnum(@ApiParam("设备id") @RequestParam(defaultValue = "100001") String deviceId,
                              @ApiParam("泊位号") @RequestParam(required = true)  String id){
        deviceOperationService.berthnum(deviceId,id);
        return ApiResult.success();

    }
    /**
     * 10.3 地锁、停车指示灯控制
     * 10.3.1 下发命令格式
     */
    @PostMapping("mcuctrl")
    @ApiOperation("地锁、停车指示灯控制")
    public ApiResult mcuctrl(@ApiParam("设备id") @RequestParam(defaultValue = "100001") String deviceId,
                             @ApiParam("指示灯") @RequestParam(defaultValue = "1") Integer lock,
                             @ApiParam("地锁") @RequestParam(defaultValue = "00") String led){
        if (!LockEnum.exist(lock) || !LedEnum.exist(led)) {
            throw new ServiceException("参数有误");
        }
        deviceOperationService.mcuctrl(deviceId,lock,led);
        return ApiResult.success();

    }

    /**
     * 10.4 查询视频充电停车设备状态
     */
    @PostMapping("devquery")
    @ApiOperation("查询视频充电停车设备状态")
    public ApiResult devquery(@ApiParam("设备id") @RequestParam(defaultValue = "100001") String deviceId){
        deviceOperationService.devquery(deviceId);
        return ApiResult.success();
    }

     /**
     * 10.5 视频充电停车设备重启
     */
    @PostMapping("devreboot")
    @ApiOperation("视频充电停车设备重启")
    public ApiResult devreboot(@ApiParam("设备id") @RequestParam(defaultValue = "100001") String deviceId){
        deviceOperationService.devreboot(deviceId);
        return ApiResult.success();
    }

    @PostMapping("rqcode")
    @ApiOperation("二维码下发协议")
    public ApiResult rqcode(@ApiParam("设备id") @RequestParam(defaultValue = "100001") String deviceId,
                            @ApiParam("二维码code") @RequestParam(required = true)String code,
                            @ApiParam("二维码类型") @RequestParam(defaultValue = "pay") String type) {
        deviceOperationService.rqcode(deviceId, code, type);
        return ApiResult.success();
    }







}
